package com.esd.db.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.esd.db.model.AlipayInfo;
import com.esd.db.model.inspectorrecord;
import com.esd.db.model.workerRecord;

public interface WorkerRecordService {
	
	List<workerRecord> getWorkerRecordLikeDownPackName(int workerId,int page, String downPackName,int row);

	int deleteByPrimaryKey(Integer recordId); 

	int insert(workerRecord record);

	int insertSelective(workerRecord record);
	
	int inserts(List<workerRecord> list);
	
	workerRecord getByPrimaryKey(Integer recordId);

	int updateByPrimaryKeySelective(workerRecord record);

	int updateByPrimaryKey(workerRecord record);
	
	int updateBydownPackName(workerRecord record);
	
	int updateByGiveUp(int workerId,int taskId,int version,String updateMethod);
	
	int updateByWorkerId(int taskEffective,int taskLockTime,int workerId,String firstDate,int inspectorId,String endDate,int inspectorrecordId);
	
	List<workerRecord> getDoingTask();
	
	List<workerRecord> getAllByWorkerId(Integer workerId,Integer taskEffective,Integer statu,String beginDate,String endDate,String taskNameCondition,int page,int row,int dateType);
	
	int getAllCountByWorkerId(Integer workerId,Integer statu,String beginDate,String endDate,String taskNameCondition,int dateType);
	
	int getCountByWorkerId(Integer workerId,Integer statu,int taskEffective);
	
	String get1DownUrlByTaskName(String taskName);
	
	int get1PkIDByTaskName(String taskName);
	
	workerRecord getWorkerRecordByWorkerId(Integer workerId);
	
	int getDoingTaskCountByWorkerId(Integer workerId);
	
	List<workerRecord> getDownNameAndTimeByWorkerIdGroupByDownPackName(Integer workerId);
	
	int getTaskCountByDownPackName(String downPackName);
	
	int getPackStatuByDownPackName(String downPackName);
	
	List<workerRecord> getAllByDownPackName(String downPackName);
	
	int getFinishTaskCountByPackId(Integer packId,Integer taskMarkTime);
	
	int getTaskMarkTimeZeroCountByPackId(Integer packId);
	
	String get1DownPackNameByTaskName(String taskName);
	
	String getDownUrlByDownPackName(String downPackName);
	
	List<workerRecord> getDownNameAndTimeByWorkerIdPagesGroupByDownPackName(Map<String, Integer> map);
	
	int getDownPackNameCountByworkerIdGroupByDownPackName(int workerId,String downPackName);
	
	int getPkIDByTaskId(Integer taskId);
	
	Double getTaskMarkTimeMonthByWorkerIdAndMonth(int workerId, String beginDate, String endDate, String userNameCondition, int taskEffective, int taskStatus,int dateType);
	
	Double getSUMTaskMarkTimeByPackId(int packId);
	
	int getPackIdByTaskId(Integer task_id);
	
	List<Map<String, Object>> getWorkerIdGroupByWorkerId(int inspectorId,String userName,int timeMark,int taskStatu,int taskEffective,int page,int row,int limitMin,String workGroupCode);

	int getWorkerIdCountGroupByWorkerId(int inspectorId,String userName,int timeMark,int taskStatu,int taskEffective,int limitMin,String workGroupCode);
    
	List<workerRecord> getByWorkerIdAndEffective(int workerId,int taskEffective,int taskStatu);

	List<Integer> getPackIdByDateTime(int workerId,String firstDate,String endDate);
	
	List<workerRecord> getInvalidTask(int page,int row);
	
	Integer getInvalidCountTask();
	
	int updateByInvalid(int inspectorId,int taskId);
	
	int getdownCountByWorkerIdAndDate(int worker_id,int dateType,String beginDate,String endDate);
	
	int getCountByWorkerIdAndDate(int worker_id,int dateType,String beginDate,String endDate,int taskStatu,int taskeffective);

	List<Map<String, Object>> getMoneyList(String beginDate,String endDate,int month);

	List<workerRecord> getAllRowByTaskId(int taskId);
	
	Date getTaskUploadTimeByWorkerId(int workerId);
	
	List<workerRecord> getTaskByWorkerId(int inspectorId,int workerId,int taskEffective,int taskStatus,String workGroupCode,String uploadUUID);
	
	int updateAduitByWorkerId2(int workerId,int taskEffective,int taskLockTime,int inspectorId,int inspectorrecordId,
			List<String> downPackNames, int salaryCountFlag, String uploadUUID, int sendBackType, int[] unqualifiedTaskIds,AlipayInfo payInfo);

	List<Integer> getPackIdByDateTime2(int workerId);
	
	List<Map<String, Object>> getWorkerHis(int workerId,int page,int row);

	int getDoingCountByTaskId(int taskId);
	
	List<Map<String, Object>> getListForInspectorByDay(String dateCondition,int page,int row,String workGroupCode, String nowString);

	int getCountForInspectorByDay(String dateCondition,String workGroupCode,String nowString);

	List<workerRecord> getTaskForInspectorByDay(String insDate, String searchTime, String workGroupCode, int inspectorId);

	int updateAduitForInspectByDay(String insDate, int taskEffective, int day, int insId, int inspectorrecordId, int[] workerIds, 
			String searchTime, String workGroupCode, int salaryCountFlag, List<AlipayInfo> payList,  List<Integer> recordIds);

	List<Integer> getPackIdForinspectorByPackage();

	int getTaskCountByPackIdForInspectorByPackage(Integer packId);

	List<Map<String, Object>> getListForInspectorByPackage(List<Integer> packIds, String insPackageCondition, int page, int row);

	int getCountForInspectorByPackage(List<Integer> packIds, String insPackageCondition);

	List<workerRecord> getTaskForInspectorByPackage(int packId);

	List<Integer> getWorkIdsByPackId(int packId);

	int updateAduitForInspectByPackage(int packId, int taskEffective, int taskLockTime, int inspectorId, int inspectorrecordId, 
			int[] workerIds, int sendBackType, int[] unqualifiedTaskIds,int salaryCountFlag, List<AlipayInfo> payList);

	List<Map<String,Integer>> getTaskIdsAndWorkerrecordIdsforInspectByDay(String insDate, String searchTime, String workGroupCode,int inspectorId);

	List<Integer> getTaskIdsforInspectByPackage(int packId);
	
	/**
	 * 核有效时间是0的任务直接审核通过用  ---查询任务id
	 * @param packId
	 * @param inspType 审核类型  包审是1   快速审核是2 
	 * @return
	 */
	List<Integer> getTaskIdsforInspectByPackageAndMarkTimeIsZero(int packId, int inspType);
	
	/**
	 * 审核有效时间是0的任务直接审核通过用  ---更新信息
	 * @param packId  包的id
	 * @param taskEffective  状态
	 * @param taskLockTime  时间
	 * @param inspectorId  审核信息id
	 * @param inspectorrecordId   审核记录id
	 * @param inspType   审核类型  按包审核是1  快速审核是2
	 * @return
	 */
	int updateAduitForInspectByPackageAndMarkTimeIsZero(int packId, int taskEffective, int taskLockTime, int inspectorId,
			int inspectorrecordId, int inspType);
	
	/**
	 * 找到已经通过按人核审的packid
	 * @return
	 */
	List<Integer> getPackageIdsForQuickInspection(String quickInspCondition);
	
	/**
	 * 查询快速审核列表用的list 
	 * @param packIds  pack的id
	 * @param quickInspCondition  查询条件 包名
	 * @param page   页数
	 * @param row   行数
	 * @return   页面显示用list
	 */
	List<Map<String, Object>> getListForQuickInspection(List<Integer> packIds, String quickInspCondition, int page, int row);
	
	/**
	 * 快速审核  审核页面显示任务列表
	 * @param packId
	 * @return
	 */
	List<workerRecord> getTaskForQuickInspection(int packId);
	
	/**
	 * 快速审核  根据packid查找相应任务的id
	 * @param packId
	 * @return
	 */
	List<Integer> getTaskIdsForQuickInspection(int packId);
	
	/**
	 * 快速审核  根据packid查找相应的workerId用于插入工资表
	 * @param packId
	 * @return
	 */
	List<Integer> getWorkIdsByPackIdForQuickInspection(int packId);
	
	/**
	 * 快速审核  更新审核信息
	 * @param packId
	 * @return
	 */
	int updateAduitForQuickInspection(int packId, int taskEffective, int taskLockTime,int inspectorId, int inspectorrecordId, 
			int[] workerIds, int salaryCountFlag, List<AlipayInfo> payList);
	
	/**
	 * 根据不同审核类型来检查任务是否已经被不合格退回超过两次 
	 * 如果超过两次则释放任务  没有超过两次增加退回记录次数 不做其他处理
	 * 通过参数来判断是哪个审核调用的此方法:
	 * 	workerIds 不能是null  因为是审核不合格时才调用次方法  而审核不合格时是肯定会有workid的
	 * 	insDate为null 并且 packId为0的话  是第一步按人审核
	 * 	insDate不为null packId为0 按天审核
	 * 	insDate为null packId不为null 按包审核或者是快速审核
	 * @param workerIds 被退回工作者id数组
	 * @param insDate   按天审核的时间
	 * @param packId    按包审核的包id
	 * @param quickInpsFlag 是否是快速审核
	 * @param workGroupCode 所属工作组代码
	 * @param sendBackType 退回类型  单个退回1  批量2    不使用时传入0
	 * @param taskIds 单个退回时被选中的任务id   不使用时传入null 
	 * @param downPackNames 按人审核按批次退回时的下载包名  不用时 传入null
	 * @param uploadUUID 按人审核用工作者上传批次uuid  不用时 传入null
	 * @param searchTime 按天审核点击查询的时间   限制审核任务的初审通过时间不晚于查询的时间
	 * @param insId 审核员id
	 * @param inspRecord 临时组装的审核记录对象
	 * @return int 返回符合当前调用条件的没有被释放的任务数
	 */
	int handleWithUnqualifiedCount(int[] workerIds, String insDate, int packId, boolean quickInpsFlag, 
			String workGroupCode, int sendBackType, int[] taskIds, List<String> downPackNames,
			String uploadUUID, String searchTime, int insId, inspectorrecord inspRecord);
	
	/**
	 * 通过任务id查找任务的下载包名
	 * @param map
	 * @return
	 */
	List<String> selectDownPackNamesByTaskIds(int workerId, int[] taskIds);
	
	/**
	 * 工作者页面显示列表用
	 * @param workerId
	 * @param taskEffective
	 * @param taskStatu
	 * @return
	 */
	List<Map<String, Object>> getShowMapListForWorkerJsp(int workerId, int taskEffective, int taskStatu);
	
	/**
	 * 审核信息用 获取工作者完成任务数
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	int getWorkerDoneTaskNumForInspectionDetail(String beginDate, String endDate, int dateType);
	
	/**
	 * 审核信息用 获取页面显示列表信息
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	List<Map<String, Object>> getDetailListForInspectionDetail(String beginDate, String endDate, int dateType);
	
	/**
	 * 查询审核员审核任务的下载次数
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return 返回map中放置各种类型的次数记录
	 */
	Map<String, Integer> getInspDownloadCount(String beginDate, String endDate, int dateType);
	
	/**
	 * 根据条件查询对应状态下未审核任务数
	 * @param taskEffective 0 未审核待初审     3已初审待巡审   4已巡审待包审   1已包审 (完成)  2  不合格
	 * @param outsourcerCodes 外包商工作组代码数据 String[]
	 * @param type  查询的类型 1是自营平台 2是外包商
	 * @return 返回未审核任务数 int
	 */
	int getUninspectorCountByTaskEffectiveAndGroupCodes(int taskEffective, String[] outsourcerCodes,int type);
	
	/**
	 * 根据工资计算节点的不同 获取未审核时间 
	 * @param workerId
	 * @param salaryCountTiming
	 * @return
	 */
	double getTaskMarkTimeForUninspection(int workerId, int salaryCountTiming);
	
	/**
	 * 查询初审阶段 未审核任务list 
	 * @return
	 */
	List<Map<String, Object>> findUninspectWorkerRecordForFirstInspection();
	
	/**
	 * 根据outBizNo查询任务list
	 * @param outBizNo
	 * @return
	 */
	List<workerRecord> queryWorkerRecordByOutBizNo(String outBizNo);
	
	/**
	 * 查询巡审未审核任务list 
	 * @return
	 */
	List<Map<String, Object>> findUninspectWorkerRecordForSecondInspection();
	
	/**
	 * 处理初审有效时间为0的任务
	 * @param workerId
	 * @param uploadUUID
	 * @param inspectorId
	 * @return
	 */
	boolean inspectionByWorkerMarkTimeIsZero(int workerId, String uploadUUID, int inspectorId);
	
	/**
	 * 修改巡审退回初审次数如果超过次数则释放任务
	 * @param recordIds
	 * @param taskIds
	 * @return
	 */
	int modifySendbackCountAndReleaseTask(List<Integer> recordIds, List<Integer> taskIds, 
			boolean releaseFlag, String inspectionSendbackUUID, int inspectorRecordId, int inspectorId);
	
	/**
	 * 巡审退回初审 更新worker record
	 * @param recordIds
	 * @param insId
	 * @param inspectorRecordId
	 */
	int updateInspectByDaySendbackWrokerRecords(List<Integer> recordIds, int inspectorRecordId, String inspectionSendbackUUID, int taskLockTime);
	
	/**
	 * 根据审核员id查询被巡审退回信息列表数据	          不包含无效任务
	 * @param inspectorId
	 * @return
	 */
	List<Map<String, Object>> querySendbackListByInspectorId(int inspectorId);
	
	/**
	 * 根据审核员id查询被巡审退回信息列表数据个数	          不包含无效任务
	 * @param inspectorId
	 * @return
	 */
	int querySendbackListCountByInspectorId(int inspectorId);
	
	/**
	 * 初审查询被退任务回列表信息         不包含无效任务
	 * @param sendbackUUID
	 * @param inspectorId
	 * @return
	 */
	List<workerRecord> querySendbackWorkerRecordBySendbackUUID(String sendbackUUID, int inspectorId);
	
	/**
	 * 更新被退回任务的状态  提交回巡审
	 * @param sendbackUUID
	 * @param inspectorId
	 * @return
	 */
	int updateWorkerRecordForModifyCompleted(String sendbackUUID, int inspectorId);
	
	/**
	 * 查询初审修改完成列表
	 */
	List<Map<String, Object>> queryModifyCompletedList();
	
	/**
	 * 巡审查询初审修改完毕列表信息         不包含无效任务
	 * @param sendbackUUID
	 * @param inspectorId
	 * @return
	 */
	List<workerRecord> queryModifyCompletedWorkerRecordBySendbackUUID(String sendbackUUID, int inspectorId);
	
	List<Map<String,Integer>> getTaskIdsAndWorkerrecordIdsforModifyCompleted(String sendbackUUID, String workGroupCode,int inspectorId);
	
	int updateAduitForModifyCompleted(int taskEffective, int insId, int inspectorrecordId, int salaryCountFlag, List<AlipayInfo> payList,  List<Integer> recordIds);
	
	/**
	 * 查询需要被系统回收的巡审退回初审的任务数
	 */
	int countReleaseTaskNum(List<Integer> recordIds, int sendbackCount);
	
	/**
	 * 根据审核员id查找被系统回收的 被巡审退回的数据
	 * @param inspectorId
	 * @return
	 */
	List<Map<String, Object>> queryRecycledBySystemListByInspectorId(int inspectorId, int page, int row);

	int queryRecycledBySystemListByInspectorIdCount(int inspectorId);
	
	/**
	 * 查询外包商初审待修改信息 
	 * @return 
	 */
	List<Map<String, Object>> queryWaitingModifyList(String[] outsourcerCodes);
	
	int releaseTasksBySendBackUUIDs(List<String> sendBackUUIDs);
	
	
	/**
	 * 根据审核员id查找被系统回收的 被巡审退回的超时为修改完成的数据
	 * @param inspectorId
	 * @return
	 */
	List<Map<String, Object>> queryModifyTimeOutListByInspectorId(int inspectorId, int page, int row);

	int queryModifyTimeOutListByInspectorIdCount(int inspectorId);

	List<Map<String, Object>> queryNotReturnNums();
	
	/**
	 * 根据工作组代码查询该工作组被退回初审未修改完成任务数
	 * @param workGroupCode
	 * @return
	 */
	int queryWaitInspModificationNumByWorkGroupCode(String workGroupCode);

	void workGroupDownloadUnlock(List<String> workGroupCodes);

	Map<String, Object> getPkIdAndUnqualifiedCountByTaskId(int taskId);
	
	/**
	 * 查询任务id 记录id textgrid文件-- 初审结算时保存md5用 
	 * @param workerId
	 * @param uploadUUID
	 * @return 返回的map里面有"recordId","taskId","bytes" bytes是byte数组需要转换类型后生成md5
	 */
	List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForAuditingUpdateFinalMd5(int workerId, String uploadUUID);
	
	/**
	 * 根据id更新finalmd5字段
	 * @param recordId
	 * @param md5
	 * @return
	 */
	int updateFinalMd5ByRecordId(int recordId, String md5);
	
	/**
	 * 查询任务id 记录id textgrid文件-- 巡审结算时保存md5用 
	 * @param workerId
	 * @param uploadUUID
	 * @return 返回的map里面有"recordId","taskId","bytes" bytes是byte数组需要转换类型后生成md5
	 */
	List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForInspectByDayUpdateFinalMd5(List<Integer> recordIds);
	
	/**
	 * 查询任务id 记录id textgrid文件-- 包审结算时保存md5用 
	 * @param workerId
	 * @param uploadUUID
	 * @return 返回的map里面有"recordId","taskId","bytes" bytes是byte数组需要转换类型后生成md5
	 */
	List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForInspectByPackageUpdateFinalMd5(int workerId, int packId);
	
	/**
	 * 查询任务id 记录id textgrid文件-- 快速审核结算时保存md5用 
	 * @param workerId
	 * @param uploadUUID
	 * @return 返回的map里面有"recordId","taskId","bytes" bytes是byte数组需要转换类型后生成md5
	 */
	List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForQuickInspectionPosteUpdateFinalMd5(int workerId, int packId);

	/**
	 * 获得查询时间内的工作者的一次性成功率
	 * @param workerId  工作者id
	 * @param beginDate  开始时间
	 * @param endDate    结束时间
	 * @param dateType   日期查询类型 
	 * @param salaryCountTiming   工资结算节点
	 * @return 返回下载任务总数 downAllNum, 未上传数 notUploadNum, 未结算数 notSettlementNum, 一次性成功数 oneTimeSuccessNum,  一次性成功率oneTimeSuccessRate
	 */
	Map<String, Object> getOneTimeSuccessRate(int workerId, String beginDate, String endDate, int dateType, int salaryCountTiming);
	
	/**
	 * 根据时间查询工作者上传任务总量
	 * @param time
	 * @return
	 */
	int queryUploadCountByDate(String queryDate);
	
	/**
	 * 根据条件查询工作者的上传时间
	 * @param dateType
	 * @param beginDate
	 * @param endDate
	 * @param userNameCondition
	 * @param workGroupCode
	 * @return Map map key : totleTime, workerId, realname, username, uninspectionTime, inspectedTime
	 */
	List<Map<String, Object>> getWorkerUploadTime(int dateType, String beginDate, String endDate, String userNameCondition,
			String workGroupCode);
	
	/**
	 * 初审查询总数  方法重载 比之前的多了个 packBatchName 用来区分批次
	 * @return
	 */
	int getWorkerIdCountGroupByWorkerId(int inspectorId, String userName, int timeMark, int taskStatu,
			int taskEffective, int limitMin, String workGroupCode, String packBatchName);
	/**
	 * 初审查询列表数据  方法重载 比之前的多了个 packBatchName 用来区分批次
	 * @return
	 */
	List<Map<String, Object>> getWorkerIdGroupByWorkerId(int inspectorId, String userName, int timeMark, int taskStatu,
			int taskEffective, int page, int row, int limitMin, String workGroupCode, String packBatchName);
	
	/**
	 * 查询工作者下载任务数  不包含退回修改数
	 * @param workerId
	 * @return
	 */
	int getWorkerDownloadTaskNumByWorkerId(int workerId);
	
	/**
	 * 修改工作者下载任务的任务时限
	 * @param workerId
	 * @param lockTime 修改的时间毫秒数
	 * @return
	 */
	int changeWorkerDownloadTaskLockTimeByWorkerId(int workerId, long lockTime);
	
	/**
	 * 初审审核修改有效时间为0的任务的有效时间为0.001
	 * @param workerId
	 * @param uploadUUID
	 * @return
	 */
	boolean updateWorkerRecordChangeZeroTo0001(int workerId, String uploadUUID);

}
